feat: Implement automatic adding of jsxImportSource pragma definition#2353
feat: Implement automatic adding of jsxImportSource pragma definition#2353emmatown merged 15 commits intoemotion-js:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 6ada9d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6ada9d9:
|
Codecov Report
|
emmatown
left a comment
There was a problem hiding this comment.
Could you change the config to be like this?
The default should be this:
{
"runtime": "classic"
}and to use the new runtime, it should be this
{
"runtime": "automatic"
}and with a custom importSource, it should be this:
{
"runtime": "automatic",
"importSource": "whatever"
}|
After I changed the implemention: { "runtime": "automatic" }{ "runtime": "automatic", "importSource": "whatever" }If your config is not oneOf [{ "runtime": "xx" }, { "runtime": "xx", "importSource": "yy" }], your code will be treated by the previous @emotion/eslint-plugin. /cc @mitchellhamilton @Andarist Hi, maintainers, do you have a little time to review my PR? Thanks |
|
Looking forward to using this! |
53997a1 to
4bdbacd
Compare
ryanrabello
left a comment
There was a problem hiding this comment.
I'm not qualified to approve this PR. But I would love to be able to use the code in here
|
I really appreciate this PR. For now, I've copied this as a local eslint rule for my project. Hopefully it can be integrated soon. I noticed one difference between classic and automatic options that I was hoping to understand better. For classic, once the jsx import rule is satisfied, these additional rules are also satisfied ( 'jsx' is defined but never used - no-unused-vars AND 'React' must be in scope when using JSX react/react-in-jsx-scope). With automatic, after the jsx import rule is satisfied, these errors are still present. I'm new to eslint rules and I was wondering what accounts for this difference? |
With the automatic runtime, that error is correct, it's unused and shouldn't be there.
That rule should be disabled when using the automatic runtime - https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md#when-not-to-use-it |


What: To fix #2070 and fix #2373
Why: when using the new fragma jsxImportSource - to automatically add the new pragma definition to the top of the file page, like already is implemented with the
oldpragma/* @jsx jsx */How: Add eslint rule support.
Checklist:
jsx-runtime
react official blog -> https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
babel support -> https://babeljs.io/docs/en/babel-plugin-transform-react-jsx#customizing-the-automatic-runtime-import
Add jsxImportSource option
It works as follows:
Add jsxImportSource custom jsx-runtime option
It works as follows:
/cc @Andarist @mitchellhamilton